<?php
	$user= new user();
	#We load the default data when a new user comes to the site
	$user->init_defaults($server->my_site[0]->subdomain . '.' . $server->my_site[0]->domain);

	$user->email=htmlentities($_POST["user_name"]);
	$user->login();	//Detects if there is any user with this email and when it isn't it sets email to null
	$user->password=htmlentities($_POST["user_password"]);
	if (!$user->email) {
		$user->email=htmlentities($_POST["user_name"]);
		$user->db_insert();
		$user->cfm_key=md5(mt_rand(1000, 9999));
		$user->cfm();
		$_SESSION["ser_user"]=serialize($user); //We save the data into the session
		
		// To send HTML mail, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

		// Additional headers
		$headers .= 'From: Cosmética <info@cosmetica.com>' . "\r\n";
		$headers .= 'Cc: melchorherrera@gmail.com' . "\r\n";

		$subject="Email de confirmación de cuenta";
		$content="Por favor vaya a la web y tras acceder a su cuenta introduzca los siguientes datos:" . "\r\n";
		$content.="Clave de confirmación de email: ".$user->cfm_key. "\r\n";
		mail($user->email,$subject,$content,$headers);

		include($server->get_path_name('user_area.php'));

	}
	else {
?>
<div class="note">
	El email introducido pertenece a un usuario existente por favor introduce tus datos de acceso.<br>
	<a href="?section=pwd_rmd" myFor="rightContentBox">Si has olvidado tu contraseña pulsa aquí.</a>
</div>

<?php
		include($server->get_path_name('login_form.php'));
	}
?>